<div class="portlet-body form">
	<!-- BEGIN FORM-->
	<?php if(isset($error_message)) echo $error_message; ?>
	<form action="#" class="form-horizontal" id="form-materi" method="post" enctype="multipart/form-data">
		<div class="control-group">
			<label class="control-label">Judul Materi</label>
			<div class="controls">
				<input type="text" class="span6 m-wrap" name="mat_name"
					value="<?php echo $mat_name;?>" /> <span class="help-inline">(Judul
					Materi)</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">Mata Pelajaran</label>
			<div class="controls">
				<select class="span6 chosen" data-placeholder="Choose a Category"
					tabindex="1" name="mp_id">
					<option value="" />Pilih Mata Pelajaran...
					<?php 
					foreach($row_mp as $row){
						$selected = "";
						if($row->mp_id == $mp_id) $selected = "selected";
						?>
					<option <?php echo $selected;?> value="<?php echo $row->mp_id;?>" />
					<?php echo $row->mp_name;?>
					<?php }?>
				</select> <span class="help-inline">(Mata Pelajaran)</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">Kelas</label>
			<div class="controls">
				<select data-placeholder="Pilih Kelas..." name="kelas[]"
					class="chosen span6" multiple="multiple" tabindex="6" id="mat_kelas">
					<option value="" />Pilih Kelas
					<?php 
					$kl_rank = '0';
					foreach ($kelas as $kls){
					$selected = '';
					if(in_array($kls->kl_id, $classes)) $selected = 'selected';
					if($kl_rank != $kls->kl_rank) echo '<optgroup label="Tingkat '.$kls->kl_rank.'">';
					?>
					<option value="<?php echo $kls->kl_id;?>" <?php echo $selected;?> />
					<?php echo $kls->kl_name;?>
					<?php if($kl_rank != $kls->kl_rank){
						echo '</optgroup>';
						$kl_rank = $kls->kl_rank;
					}
				}?>
				</select> <span class="help-inline">(Kelas)</span>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">Upload</label>
			<div class="controls">
				<div class="fileupload fileupload-new" data-provides="fileupload">
					<div class="input-append">
						<div class="uneditable-input">
							<i class="icon-file fileupload-exists"></i> <span
								class="fileupload-preview"></span>
						</div>
						<span class="btn btn-file"> <span class="fileupload-new">Pilih
								file</span> <span class="fileupload-exists">Ubah</span> <input
							type="file" class="default" name="mat_file" />
						</span> <a href="#" class="btn fileupload-exists"
							data-dismiss="fileupload">Hapus</a>
					</div>
				</div>
				 <span class="help-inline">(Format file yang diperbolehkan : txt, doc, docx, pdf, zip, rar)</span>
			</div>
		</div>


		<input type="hidden" class="span6 m-wrap" name="mat_id"
			value="<?php echo $id;?>" />
		<div class="form-actions">
			<button type="submit" class="btn blue">Submit</button>
			<a href="<?php echo base_url().$menu;?>" class="btn grey">Cancel</a>
		</div>
	</form>
	<!-- END FORM-->
</div>
<div class="dialog" id="loading-scr">
	<img border="0" src="<?php echo base_url();?>images/loading.gif" alt=""
		style="margin-top: 20%;">
</div>


<style>
.dialog {
	z-index: 99;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.5);
	display: none;
	position: fixed;
	left: 0;
	top: 0;
	text-align: center;
}
</style>
<script type="text/javascript">
	var options = {
    	clearForm: false,
		url : "<?php echo base_url();?>materi/action/insert",
	    success: function(responseText, statusText, xhr, $form){
			$('#loading-scr').css({'display': 'none',});
			alert(responseText);
			if(responseText == "Success") window.location.href = "<?php echo base_url();?>materi";
		},
		error : function(){
    		$('#loading-scr').css({'display': 'none',});
		},
		beforeSubmit: beforeSubmit,
    };
	$(document).ready(function() {
		$("#form-materi").ajaxForm(options).submit(function(){
			return false;
		});
	});
	
	function beforeSubmit(arr, $form, options){
		var callback = true;
		$.each(arr, function(i, data){
			if(!data.value){
				if(data.name!="mat_file"){
					callback = false;
				}
			}
		});         
		if(!callback) alert("Isi semua kolom");
		else $('#loading-scr').css({'display': 'block',});
		return callback;
	};
</script>
